using System;
using System.Collections.Generic;
using Me.Prettyprint.Cassandra.Serializers;
using Me.Prettyprint.Cassandra.Service;
using Me.Prettyprint.Hector.Api;
using Me.Prettyprint.Hector.Api.Beans;
using Me.Prettyprint.Hector.Api.Factory;
using Me.Prettyprint.Hector.Api.Query;
using Org.Apache.Cassandra.Thrift;
namespace Me.Prettyprint.Cassandra.Model
{
    /// <summary>
    /// Base class for slice query classes to extend.
    /// </summary>
    /// <typeparam name="K"></typeparam>
    /// <typeparam name="N"></typeparam>
    /// <typeparam name="V"></typeparam>
    /// <typeparam name="T"></typeparam>
    public abstract class AbstractSliceQuery<K, N, V, T> : AbstractQuery<K, N, V, T>, Query<T>
    {
        public AbstractSliceQuery(Keyspace k, Serializer<K> keySerializer, Serializer<N> nameSerializer, Serializer<V> valueSerializer) : base(k, keySerializer, nameSerializer, valueSerializer)
        {
            SlicePredicate = new HSlicePredicate<N>(nameSerializer);
        }
        public HSlicePredicate<N> SlicePredicate
        {
            get;
            set;
        }
        public Query<T> SetColumnNames(List<N> columnNames)
        {
            if (columnNames != null && columnNames.Count > 0)
            {
                SlicePredicate.SetColumnNames(columnNames);
            }
            else
            {
                SlicePredicate.SetKeysOnlyPredicate();
            }
            return this;
        }
        public List<N> ColumnNames
        {
            get
            {
                return SlicePredicate.ColumnNames;
            }
        }
        public virtual Query<T> SetRange(N start, N finish, bool reversed, int count)
        {
            SlicePredicate.SetRange(start, finish, reversed, count);
            return this;
        }
        protected string ToStringInternal()
        {
            return SlicePredicate.ToString();
        }
        public SlicePredicate GetPredicate()
        {
            return SlicePredicate.ToThrift();
        }
        public AbstractSliceQuery<K, N, V, T> SetReturnKeysOnly()
        {
            SlicePredicate.SetKeysOnlyPredicate();
            return this;
        }
    }
}